Skip to content

Conversation

@AndreiDreyer
Copy link
Contributor

use Trait in Php acts like interfaces that allow you to override methods or call the base method implemented in the trait. We simply add the trait name to the inheritsFrom field. It's also been tested, the use Trait call can be anywhere in the class definition but still acts like it was called at the top of the class definition.

trait TraitA {
  function traitFunc() {}
}

class Foo {
  use TraitA;
  function someFunc() {
    $this->traitFunc();
  }
}

(new Foo()).traitFunc();

@AndreiDreyer AndreiDreyer requested a review from ml86 July 30, 2025 13:07
@AndreiDreyer AndreiDreyer self-assigned this Jul 30, 2025
@TNSelahle TNSelahle force-pushed the andrei/php-implement-use-trait branch from 2214c2a to b7dbee1 Compare November 4, 2025 08:50
@TNSelahle TNSelahle merged commit 5db8a97 into master Nov 4, 2025
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants